<?php
class UsersController extends AppController{
    var $name='Users';
    
    
    function index(){
        $this->redirect('login');
    }
    
    function login(){
        // if the form has been submitted   
        if(!empty($this->data)) {   
            // check the username and password   
            if( ($user = $this->User->check_login($this->data)) ) {   
                // save the user information to the session   
                $this->Session->write('User', $user);
                //$this->User->query('UPDATE users SET users.last_login='.date('Y-m-d H:i:s',time()).' WHERE id='.$this->User->id);   
                // set flash messsage   
                $this->Session->setFlash('You have successfully logged in.');   
                // redirect the user   
                $this->redirect('/users/main/');   
            } else {   
                // set error message   
                $this->Session->setFlash('ERROR: Invalid Username or Password.');   
            }   
        }   
    }
    
    function logout() {   
        // delete the User session   
        $this->Session->delete('User');   
        // set flash message   
        $this->Session->setFlash('You have successfully logged out.');   
        // redirect the user   
        $this->redirect(array('action'=>'login', 'controller'=>'users'));    
    }
    
    function main(){
             
    }
}  
?>
